<template>
  <a-layout-header :class="[theme.mode, 'admin-header']">
    <div :class="['admin-header-wide', layout, pageWidth, target]">
      <router-link v-if="isMobile || layout === 'head'" to="/" :class="['logo', isMobile ? null : 'pc', theme.mode]">
        <img width="93" :src="require('@/assets/img/'+logoImg)" />
      </router-link>
      <!-- <a-divider v-if="isMobile" type="vertical" /> -->
      <a-icon v-if="layout !== 'head'" class="trigger" :type="collapsed ? 'menu-unfold' : 'menu-fold'" @click="toggleCollapse"/>
      <div v-if="layout !== 'side' && !isMobile" class="admin-header-menu" style="width:calc(100% - 588px);">
        <i-menu class="head-menu" :theme="theme.mode" mode="horizontal" :options="menuData" @select="onSelect"/>
      </div>
      <div :class="['admin-header-right', theme.mode]">
        <header-search />
        <header-avatar class="header-item"/>
      </div>
    </div>
  </a-layout-header>
</template>

<script>
import HeaderAvatar from './HeaderAvatar'
import HeaderSearch from './HeaderSearch'
import IMenu from '@/components/menu/menu'
import {mapState} from 'vuex'


export default {
  name: 'AdminHeader',
  components: {IMenu, HeaderAvatar, HeaderSearch},
  props: ['collapsed', 'menuData','target'],
  data() {
    return {
    }
  },
  computed: {
    ...mapState('setting', ['theme', 'isMobile', 'layout', 'systemName', 'pageWidth']),
    headerTheme () {
      if (this.layout == 'side' && this.theme.mode == 'dark' && !this.isMobile) {
        return 'light'
      }
      return this.theme.mode
    },
    logoImg(){
      if((this.target=='window'&&this.theme.mode=='light')||(this.target=='home'&&this.theme.mode=='night')){
        return 'logo.png'
      }else{
        return 'logo_night.jpg'
      }
    }
  },
  methods: {
    toggleCollapse () {
      this.$emit('toggleCollapse')
    },
    onSelect (obj) {
      this.$emit('menuSelect', obj)
    },

  }
}
</script>

<style lang="less" scoped>
@import "index";
</style>
